<template>
  <div class="mflist" @click="gettitl">
    <loading v-if="isLoading"></loading>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">好书专区</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[0]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}|<span>完结</span></p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <em>免费</em
                  ><del>{{ (item.clickCount / 100).toFixed(0) }}阅点</del>
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <div class="hed">
      <hr />
      <h3 class="f-cb">
        <span class="gradient">猜你喜欢</span>
        <router-link to class="more">更多</router-link>
      </h3>
      <div class="booklist">
        <ul>
          <li v-for="(item, s) in book_list[1]" v-if="s < 3">
            <router-link :to="`/cs?id=${item.id}`">
              <div class="book-1">
                <img :src="item.cover" alt="" />
              </div>
              <div class="text-1">
                <h4>{{ item.title }}</h4>
                <p class="name-1">{{ item.author }}|<span>完结</span></p>
                <p class="p-1">
                  {{ item.content }}
                </p>
                <p class="tag-1">
                  <em>免费</em
                  ><del>{{ (item.clickCount / 100).toFixed(0) }}阅点</del>
                </p>
              </div>
            </router-link>
          </li>
        </ul>
      </div>
    </div>
    <!-- <div class="butom"></div> -->
  </div>
</template>
<script>
import { recommendFunc, reFunc } from "@/request/index";
import Loading from "@/components/loading/indexlist.vue";
export default {
  data() {
    return {
      book_list: [],
      url: "",
      title: "",
      isLoading: true,
    };
  },
  components: {
    Loading
  },
  methods: {
    async csfe() {
      await recommendFunc().then((res) => {
        // console.log(res.data);
        let { navi } = res.data;
        this.url = navi[3].url;
        // console.log(navi);
        reFunc(navi[1].url).then((lis) => {
          // console.log(lis);
          let { list } = lis.data;
          // console.log(list);
          // 整合数据
          // let{list}=list
          this.book_list = list.map((item) => {
            // console.log(item);
            // console.log(list);
            return item.list;
          });
          // console.log(this.book_list);
        }).catch(err => {
          console.log("请求失败...");
        });
        this.isLoading = false;
      }).catch(err => {
          console.log("请求失败...");
        });
    },
    gettitl(e) {
      if (e.target.textContent === "更多") {
        this.title = e.target.parentNode.firstChild.textContent;
      }
      let titles= this.title
      let urls = this.url
      this.$router.push(`/modo?list_title=${titles}&url=${urls}`);
    },
  },
  created() {
    this.csfe();
  },
};
</script>
<style lang="scss">
@import url(../../static/css/reset.css);

.mflist {
  margin: auto 5%;
  margin-top: 3px;
  .hed {
    width: 100%;
    h3 {
      height: 28px;
      line-height: 28px;
      margin-bottom: 16px;
      font-weight: bold;
      .gradient {
        float: left;
        display: inline-block;
        font-size: 20px;
        color: #1a1a1a;
      }
      .more {
        float: right;
        padding: 0 17px;
        font-size: 13px;
        font-weight: normal;
        color: #999;
        box-sizing: border-box;
        border: 1px solid #f0f0f0;
        border-radius: 28px;
      }
    }
    .booklist {
      margin-top: 20px;
      width: 100%;
      // background: black;
      ul {
        li {
          position: relative;
          display: flex;
          width: 100%;
          &:before {
            position: absolute;
            top: 7px;
            left: 5px;
            display: inline-block;
            content: "";
            width: 32px;
            height: 20px;
            background: url(../../static/imgs/icon_free.png);
            background-repeat: no-repeat;
            background-size: cover;
          }
          [class^="book"] {
            width: 93px;
            margin: 9px;
            float: left;
            img {
              width: 94px;
              height: 132px;
              border-radius: 5px;
            }
          }
          [class^="text"] {
            padding-top: 10px;
            color: #333;
            outline: none;
            padding-left: 10px;
            text-align: start;
            h4 {
              font-size: 15px;
              line-height: 19px;
              height: 38px;
              max-height: 38px;
            }
            [class^="name"] {
              color: #888;
              line-height: 15px;
              height: 15px;
              font-size: 12px;
              margin-bottom: 5px;
              -webkit-line-clamp: 2;
              overflow: hidden;
              span {
                margin-left: 2px;
              }
            }
            [class^="p"] {
              color: #888;
              line-height: 18px;
              height: 36px;
              -webkit-line-clamp: 2;
              display: -webkit-box;
              -webkit-box-orient: vertical;
              overflow: hidden;
              text-overflow: ellipsis;
            }
            [class^="tag"] {
              padding-top: 13px;
              em {
                float: left;
                line-height: 23px;
                margin-right: 4px;
                font-size: 12px;
                font-weight: normal;
                color: #e64d2e;
              }
              del {
                font-size: 11px;
                text-decoration: line-through;
              }
            }
          }
        }
      }
    }
  }
}
</style>
  